package com.repair.base.result;

import com.repair.base.utils.ResponseCode;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * @author chunyu
 * @since 2024/10/4,20:49
 */
@Getter
@Setter
public class PageResult<T> extends JsonResult<List<T>>{

    private int total;
    private int pageSize;
    private int currentPage;
    private int totalPage;

    public PageResult(Integer code, String message, List<T> data) {
        super(code, message, data);
    }

    public PageResult(Integer code, String message) {
        super(code, message);
    }

    public PageResult(ResponseCode responseCode, List<T> data) {
        super(responseCode, data);
    }

    public static <T> PageResult<T> ok(List<T> data, int total, int pageSize, int currentPage, int totalPage) {
        PageResult<T> result = new PageResult<>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMessage(), data);
        result.setTotal(total);
        result.setPageSize(pageSize);
        result.setCurrentPage(currentPage);
        result.setTotalPage(totalPage);
        return result;
    }

}
